package day1227;

import javax.swing.*;
import java.util.ArrayList;

public class TestZ {
    public static void main(String[] args) {
        ArrayList<String> though = new ArrayList<>();
        though.add("A");
        though.add("B");
        though.add("B");
        though.add("C");
        though.add("C");
        though.add("D");

        String selected="C";
        int found = -1;
        for (int i=0; i<though.size(); i++){
            String card = though.get(i);
            if (card.equals(selected)){
                though.add(i, selected);
                found = i;
                break;
            }
        }
        System.out.println(though);


        //相同按钮到最后一个按钮至少有三个时，判断是否要消除
        if (found != -1  && though.size()-found >= 3){
            String nextNextBtn= though.get(found+2);
            if(selected.equals(nextNextBtn)){
                though.remove(found);
                though.remove(found);
                though.remove(found);
            }
        }
        System.out.println(though);
    }
}
